from threading import Thread
from time import sleep


class MyThread(Thread):
    def __init__(self, name):
        Thread.__init__(self)
        self.name = name

    def run(self):
        for i in range(3):
            print(f'{self.name}的第{i}次执行')
            sleep(1)


if __name__ == '__main__':
    t1 = MyThread('t1')
    print('----主线程启动----')
    t1.daemon = True  # 属性应该在线程自动前设置，线程启动后则无法变更线程属性
    # DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead t1.setDaemon(True)
    # t1.setDaemon(True)
    t1.start()

    print('----主线程结束----')
